package com.jack.leetcode.eachproblem_2020;

public class 计数质数 {

    public static void main(String[] args) {
        countPrimes(10000);
    }

    public static int countPrimes(int n) {
        if(n == 0 || n == 1){
            return 0;
        }
        int result = 0;
        boolean[] dp = new boolean[n];
        int index = 2;
        while(index < n){
            if(!dp[index]){
                result++;
                for(int i = index + index;i < n;i += index){
                    dp[i] = true;
                }
            }
            index++;
        }
        return result;
    }
}
